package com.ctvit.breadking.news.xfyun.controller;

import com.ctvit.breadking.news.xfyun.service.GlobalTranslationService;
import com.ctvit.breadking.news.xfyun.service.MachineTranslationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("xfyun")
public class MachineTranslationController {

    private final MachineTranslationService machineTranslationService;

    private final GlobalTranslationService globalTranslationService;

    public MachineTranslationController(MachineTranslationService machineTranslationService, GlobalTranslationService globalTranslationService) {
        this.machineTranslationService = machineTranslationService;
        this.globalTranslationService = globalTranslationService;
    }

    @RequestMapping("translate")
    public boolean translate(@RequestParam String text) {
        return machineTranslationService.translate(text);
    }

    @RequestMapping("global")
    public boolean global(@RequestParam String text) throws Exception {
        // 西班牙语：Al menos 22 muertos y decenas de heridos en un ataque israelí contra el Centro de Beirut
        // 葡萄牙语：Israel ataca o centro da cidade de Beirute, causando pelo menos 22 mortes e dezenas de feridos
        // 斯瓦希里语：Israel ilishambulia kituo cha jiji la Beirut, na kusababisha vifo 22 na maelfu kujeruhiwa
//        String text = "At least 22 killed, scores injured as Israeli strike hits central Beirut";
//        String text = "France’s minority government is expected to survive a no-confidence vote on Tuesday in a test for new conservative Prime Minister Michel Barnier, forced to rely on the far right’s good will to be able to stay in power. " +
//                "It comes as Barnier’s fragile government faces a major challenge to get a budget for next year approved with no majority at parliament. " +
//                "Following June-July parliamentary elections, the National Assembly, France’s powerful lower house of parliament, is divided into three major blocs: the New Popular Front, Macron’s centrist allies and the far-right National Rally party. None of them won an outright majority. " +
//                "The no-confidence motion was brought by 192 lawmakers of a left-wing coalition, the New Popular Front, composed of the hard-left France Unbowed, Socialists, Greens and Communists. It needs 289 votes to pass.";
        return globalTranslationService.translate(text);
    }

}
